<?php
namespace app\shop\controller\api;

use cubox\Controller;

class Index extends Controller{
    public function onInit(){

        $cache = $this->cache();

        $coupon_name = $this->getCacheName('coupon_list');

        $re = [];

        if ($cache->has($coupon_name)){
            $re['coupon_list'] = $cache->get($coupon_name);
        }else{
            $coupon = $this->model('Coupon');
            $list  = $coupon->where('status','sale')->getData();
            $re['coupon_list'] = [];
            foreach($list as $k=>$v){
                $re['coupon_list'][$v['coupon_id']]= $v;
            }
            $cache->set($coupon_name,$re['coupon_list']);
        }
    }
}